import Cookies from 'js-cookie'

const TokenKey = 'token'

export function getToken() {
    return Cookies.get(TokenKey)
}

export function setToken(token) {
    return Cookies.set(TokenKey, token)
}

export function removeToken() {
    return Cookies.remove(TokenKey)
}
const AppIdKey = 'appid'

function randomString(len) {
    len = len || 32;
    var $chars = '';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (let i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}

export function getAppId() {
    let appId = Cookies.get(AppIdKey);

    // if (!appId) {
    //     appId = randomString();
    //     setAppId(appId);
    // }

    return appId;
}

export function setAppId(appId) {
    return Cookies.set(AppIdKey, appId)
}

export function removeAppId() {
    return Cookies.remove(AppIdKey)
}